home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / Perl_WWW_Utilities / MHonArc / lib / osinit.pl < prev    next >
Encoding:
Perl Script  |  1996-03-11  |  3.1 KB  |  84 lines

  1. ##---------------------------------------------------------------------------##
  2. ##  File:
  3. ##      osinit.pl
  4. ##  Author:
  5. ##      Earl Hood       ehood@convex.com
  6. ##  Description:
  7. ##    A library for setting up a script based upon the OS the script
  8. ##    is running under.  The main routine defined is OSinit.  See
  9. ##    the routine for specific information.
  10. ##  Date:
  11. ##    Mon Mar 11 15:52:12 CST 1996
  12. ##---------------------------------------------------------------------------##
  13. ##    Copyright (C) 1995    Earl Hood, ehood@convex.com
  14. ##
  15. ##    This program is free software; you can redistribute it and/or modify
  16. ##    it under the terms of the GNU General Public License as published by
  17. ##    the Free Software Foundation; either version 2 of the License, or
  18. ##    (at your option) any later version.
  19. ##
  20. ##    This program is distributed in the hope that it will be useful,
  21. ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. ##    GNU General Public License for more details.
  24. ##
  25. ##    You should have received a copy of the GNU General Public License
  26. ##    along with this program; if not, write to the Free Software
  27. ##    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. ##---------------------------------------------------------------------------##
  29.  
  30. package os_init;
  31.  
  32. ##---------------------------------------------------------------------------##
  33. ##    OSinit() checks what operating system we are running on set
  34. ##    some global variables that can be used by the calling routine.
  35. ##    All global variables are exported to package main.
  36. ##
  37. ##    Variables set:
  38. ##
  39. ##        $'MSDOS    => Set to 1 if running under MS-DOS/Windows
  40. ##        $'MACOS    => Set to 1 if running under Mac
  41. ##        $'UNIX    => Set to 1 if running under Unix
  42. ##        $'DIRSEP    => Directory separator character
  43. ##        $'CURDIR    => Current working directory
  44. ##        $'PROG    => Program name with leading pathname component
  45. ##               stripped off.
  46. ##
  47. ##    If running under a Mac and the script is a droplet, command-line
  48. ##    options will be prompted for unless $noOptions argument is
  49. ##    set to true.
  50. ##
  51. sub main'OSinit {
  52.     local($noOptions) = shift;
  53.  
  54.     ##  Check what system we are executing under
  55.     local($tmp);
  56.     if (($tmp = $ENV{'COMSPEC'}) && ($tmp =~ /[a-zA-Z]:\\/) && (-e $tmp)) {
  57.         $'MSDOS = 1;  $'MACOS = 0;  $'UNIX = 0;
  58.     $'DIRSEP = '\\';  $'CURDIR = '.';
  59.     } elsif (defined($MacPerl'Version)) {
  60.         $'MSDOS = 0;  $'MACOS = 1;  $'UNIX = 0;
  61.     $'DIRSEP = ':';  $'CURDIR = ':';
  62.     } else {
  63.         $'MSDOS = 0;  $'MACOS = 0;  $'UNIX = 1;
  64.     $'DIRSEP = '/';  $'CURDIR = '.';
  65.     }
  66.     ##    Store name of program
  67.     ($tmp = $'DIRSEP) =~ s/(\W)/\\$1/g;
  68.     ($'PROG = $0) =~ s%.*[$tmp]%%o;
  69.  
  70.     ##    Ask for command-line options if script is a Mac droplet
  71.     ##        Code taken from the MacPerl FAQ
  72.     if (!$noOptions && ( $MacPerl'Version =~ /Application$/ )) {
  73.     # we're running from the app
  74.     local( $cmdLine, @args );
  75.     $cmdLine = &MacPerl'Ask( "Enter command line options:" );
  76.     require "shellwords.pl";
  77.     @args = &shellwords( $cmdLine );
  78.     unshift( @'ARGV, @args );
  79.     }
  80. }
  81.  
  82. ##---------------------------------------------------------------------------##
  83. 1;
  84.